// 引入模块,创建接口
const express = require('express');
const pool = require('../pool.js');
const app = express.Router();

// 请求酒店数据
app.get('/hotel', (req, res) => {
    let sql = 'SELECT * FROM Hotel_list';
    pool.query(sql, (err, results) => {
        if (err) throw err;
        res.send({
            message: 'ok',
            code: 200,
            results: results
        })
    })
})
// 根据酒店分类查询
app.get('/classify', (req, res) => {
    let obj = req.query.gender
    let sql = 'SELECT * FROM   Hotel_list where genre=?';
    pool.query(sql, [obj], (err, results) => {
        if (err) throw err;
        res.send({
            message: 'ok',
            code: 200,
            results: results
        })
    })
})


// 查询酒店宴厅信息
app.get('/hotelMsg', (req, res) => {
    let info = req.query;
    let sql = 'SELECT * FROM wedding_banquet where hotel_id=?';
    pool.query(sql, [info.id], (err, results) => {
        if (err) throw err;
        res.send({
            message: 'ok',
            code: 200,
            results: results
        })
    })

})
// 查询酒店菜品
app.get('/hotelmenu', (req, res) => {
    let info = req.query;
    console.log(info)
    let sql = 'SELECT * FROM hotel_menu where hotel_id=?';
    pool.query(sql, [info.id], (err, results) => {
        if (err) throw err;
        res.send({
            message: 'ok',
            code: 200,
            results: results
        })
    })

})
// 获取酒店地理位置优惠等信息
app.get('/hotelInfo',(req,res)=>{
    let info = req.query;
    let sql = 'SELECT * FROM hotel_msg where hotel_id=?';
    pool.query(sql, [info.id], (err, results) => {
        if (err) throw err;
        res.send({
            message: 'ok',
            code: 200,
            results: results
        })
    })  
})
// 搜索
app.get('/queryHotel',(req,res)=>{
    let info = req.query.name;
    let sql = 'SELECT * FROM Hotel_list where headline like ?';
    pool.query(sql, "%"+info+"%", (err, results) => {
        if (err) throw err;
        res.send({
            message: 'ok',
            code: 200,
            results: results
        })
    })  
})


//导出用户路由模块
module.exports = app;